package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.MemberService;
import com.itheima.OrderService;
import com.itheima.SetmealService;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Order;
import com.itheima.pojo.OrderInfoVCS;
import com.itheima.pojo.Setmeal;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/telephoneOrder")
public class TelephoneOrderController {

    @Reference
    private SetmealService setmealService;

    @Reference
    private MemberService memberService;

    @Reference
    private OrderService orderService;

    /*回显套餐列表*/
    @RequestMapping("/findAll")
    private Result findAll(){
        try {
            /*回显套餐的 id 和 name*/
           List<Setmeal> setmealList = setmealService.queryAll();
            return Result.success("",setmealList);
        } catch (Exception e) {
            return Result.error("");
        }
    }

    //分页查询
    @RequestMapping("/pageQuery")
    public PageResult pageQuery(@RequestBody QueryPageBean page){
        return memberService.pageQuery(page.getCurrentPage(),page.getPageSize(),page.getQueryString());
    }

    @RequestMapping("/addOrder")
    public Result submit(@RequestBody OrderInfoVCS orderInfoVCS) {

        //TODO : 前台传回的结果的格式    身份证号 ：idCard
        //      {setmealId:12, idCard:'412824199510301414', sex:'1', name:'吴云龙', validateCode:'949336', telephone:'15044290589', orderDate:'2019-09-28'}


        try {
            /*预约类型是微信预约，将此预约类型传到后台去*/
            orderInfoVCS.setOrderType(Order.ORDERTYPE_TELEPHONE);
            //orderInfoVCS.
            //2、验证码输入正确，将预约信息传到后台进行存储
            return orderService.phoneOrder(orderInfoVCS);
        } catch (Exception e) {
            return Result.error("预约失败");
        }

    }
}
